/*
package com.findviewbydream.evil.eda.Login;

import android.Manifest;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;

import com.dd.CircularProgressButton;
import com.findviewbydream.evil.eda.Bean.UserBean;
import com.findviewbydream.evil.eda.Data.Data;
import com.findviewbydream.evil.eda.Data.UserData;
import com.findviewbydream.evil.eda.MainActivity;
import com.findviewbydream.evil.eda.R;
import com.findviewbydream.evil.eda.Utils.Dialog.CustomMaterialDialog;
import com.findviewbydream.evil.eda.Utils.Encryp_AES;
import com.findviewbydream.evil.eda.Utils.NetUtils;
import com.findviewbydream.evil.eda.Utils.SAcp;
import com.findviewbydream.evil.eda.Utils.SuperToast.ButtonToast;
import com.findviewbydream.evil.eda.Utils.SuperToast.OnClick;
import com.findviewbydream.evil.eda.Utils.SuperToast.SuperToast;
import com.findviewbydream.evil.eda.Utils.Utils;
import com.findviewbydream.evil.eda.View.LScrollView;
import com.flyco.dialog.listener.OnBtnClickL;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.regex.Pattern;

import eightbitlab.com.blurview.BlurView;
import eightbitlab.com.blurview.RenderScriptBlur;
import okhttp3.Call;

*/
/********************************************
 * 工程名：Eda
 * 包名：com.findviewbydream.evil.eda.Login
 * 时间：16-7-22 上午11:21
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：登陆界面
 ********************************************//*

public class Login extends AppCompatActivity
{
    private ImageView login_background;
    private ImageView login_eda;
    private TextInputEditText userPhoneNum;
    private TextInputLayout userPhoneNum_Layout;
    private TextInputEditText userPassword;
    private TextInputLayout userPassword_Layout;
    private CheckBox rememberPassword;
    private CheckBox forgetPassword;
    private CircularProgressButton submit;
    private ImageView pull_down;
    private BlurView blurView;
    private BlurView blurView2;
    protected static LScrollView scrollView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        initView();*/
/*初始化控件*//*

        initBackground();*/
/*初始化背景图片*//*


        new Register().onCreate(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
            setupBlurView();*/
/*设置下拉模糊*//*


        setTextInputLayout();*/
/*设置输入正则*//*

        setPull_down();*/
/*下拉注册动画*//*

        setSubmit();*/
/*设置提交按钮监听事件*//*

        setCheckBox();*/
/* 设置 记住密码 和 忘记密码*//*


        submit.setIndeterminateProgressMode(true);

        readUserInformation();*/
/*读取用户信息，将解码的信息呈现到EditText上*//*

    }

    */
/**
     * 初始化控件
     *//*

    private void initView()
    {
        login_background = (ImageView) findViewById(R.id.login_background);
        login_eda = (ImageView) findViewById(R.id.login_eda);
        userPhoneNum = (TextInputEditText) findViewById(R.id.userPhoneNum);
        userPhoneNum_Layout = (TextInputLayout) findViewById(R.id.userPhoneNum_Layout);
        userPassword = (TextInputEditText) findViewById(R.id.userPassword);
        userPassword_Layout = (TextInputLayout) findViewById(R.id.userPassword_Layout);
        submit = (CircularProgressButton) findViewById(R.id.login_submit);
        pull_down = (ImageView) findViewById(R.id.pull_down);
        blurView = (BlurView) findViewById(R.id.blurView);
        blurView2 = (BlurView) findViewById(R.id.blurView2);
        scrollView = (LScrollView) findViewById(R.id.scrollView);
        rememberPassword = (CheckBox) findViewById(R.id.rememberPassword);
        forgetPassword = (CheckBox) findViewById(R.id.forgetPassword);
    }

    */
/**
     * 初始化背景及其其他图片
     *//*

    private void initBackground()
    {
        Utils.Glide(R.drawable.login_background, login_background);
        Utils.Glide(R.drawable.eda, login_eda);
    }

    */
/**
     * 设置输入正则
     *//*

    private void setTextInputLayout()
    {
        userPhoneNum_Layout.setHint("请输入您的手机号");
        EditText userPhoneNum = userPhoneNum_Layout.getEditText();

        if (userPhoneNum != null)
        {
            userPhoneNum.addTextChangedListener(new TextWatcher()
            {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after)
                {
                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count)
                {
                    if (s.length() != 11)
                    {
                        userPhoneNum_Layout.setError("请输入正确的手机号");
                        userPhoneNum_Layout.setErrorEnabled(true);
                    }
                    else
                    {
                        userPhoneNum_Layout.setErrorEnabled(false);
                    }
                }

                @Override
                public void afterTextChanged(Editable s)
                {
                }
            });
        }

        userPassword_Layout.setHint("请输入密码");
        EditText userPassword = userPassword_Layout.getEditText();
        if (userPassword != null)
        {
            userPassword.addTextChangedListener(new TextWatcher()
            {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after)
                {
                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count)
                {
                    if (s.length() > 20)
                    {
                        userPassword_Layout.setError("密码过长!");
                        userPassword_Layout.setErrorEnabled(true);
                    }
                    else if (s.length() < 6)
                    {
                        userPassword_Layout.setError("密码过短!");
                        userPassword_Layout.setErrorEnabled(true);
                    }
                    else if (!Pattern.compile("[a-z0-9A-Z_]+")
                            .matcher(s).matches())
                    {
                        userPassword_Layout.setError("密码仅为数字、字母、下划线！");
                        userPassword_Layout.setErrorEnabled(true);
                    }
                    else
                        userPassword_Layout.setErrorEnabled(false);
                }

                @Override
                public void afterTextChanged(Editable s)
                {

                }
            });
        }
    }

    */
/**
     * 设置提交按钮
     *//*

    private void setSubmit()
    {
        submit.setOnClickListener(view -> {
            */
/*登陆*//*

            if (submit.getProgress() == -1 || submit.getProgress() == 100)
                submit.setProgress(0);
            else
            {
                submit.setProgress(50);
                UserBean bean = new UserBean();

                */
/*判断手机号码*//*

                if (userPhoneNum.getText().toString().length() != 11)
                {
                    SuperToast.buttonToast(Login.this)
                            .setBackgroundColor(ButtonToast.Background.RED)
                            .setText("请输入正确的手机号码")
                            .show();
                    submit.setProgress(-1);
                }
                else if (userPassword.getText().toString().length() < 6
                        || userPassword.getText().toString().length() > 20)
                {
                    SuperToast.buttonToast(Login.this)
                            .setBackgroundColor(ButtonToast.Background.RED)
                            .setText("请检查密码长度")
                            .show();
                    submit.setProgress(-1);
                }
                else if (!Pattern.compile("[a-z0-9A-Z_]+")
                        .matcher(userPassword.getText().toString()).matches())
                {
                    SuperToast.buttonToast(Login.this)
                            .setBackgroundColor(ButtonToast.Background.RED)
                            .setText("密码仅为数字、字母、下划线！")
                            .show();
                    submit.setProgress(-1);
                }
                else
                {
                    //toNetWork();
                    getIMEI();*/
/*先获取到IMEI，才能联网，否则崩溃*//*

                }
            }
        });
    }

    */
/**
     * 获得IMEI
     * 获取权限
     *//*

    private void getIMEI()
    {
        new SAcp()
        {
            @Override
            public void onGranteds()
            {
                UserData.setUserIMEI(Utils.getIMEI());
                saveUserInformation();*/
/*保存用户信息*//*

                toNetWork();*/
/*执行登陆联网*//*

            }

            @Override
            public void onDenieds()
            {
                SAcp.showDialog(Login.this, Login.this);
            }
        }.getPermissions(Manifest.permission.READ_PHONE_STATE);
    }

    */
/**
     * 登陆的网络连接
     *//*

    private void toNetWork()
    {
        UserBean bean = new UserBean();
        UserData.setUserPhoneNum(userPhoneNum.getText().toString());
        bean.setUserPhone(userPhoneNum.getText().toString());
        bean.setUserPassword(Encryp_AES.encryptCode(userPassword.getText().toString()));
        bean.setUserIMEI(Utils.getIMEI());

        OkHttpUtils.post().url(Data.IP + "LoginServlet")
                .addParams("type", "login")
                .addParams("phone", bean.getUserPhone())
                .addParams("imei", bean.getUserIMEI())
                .build()
                .execute(new StringCallback()
                {
                    @Override
                    public void onError(Call call, Exception e, int id)
                    {
                        e.printStackTrace();
                        NetUtils.reportError(Login.this, e);
                        submit.setProgress(-1);
                    }

                    @Override
                    public void onResponse(String response, int id)
                    {
                        if (response.equals("SUCCESS"))
                        {
                            submit.setProgress(100);
                            startActivity(new Intent(Login.this, MainActivity.class));
                            finish();
                        }
                        else if (response.equals("FAILE"))
                        {
                            SuperToast.buttonToast(Login.this)
                                    .setBackgroundColor(ButtonToast.Background.RED)
                                    .setText("密码错误！")
                                    .show();
                            submit.setProgress(-1);
                        }
                        else if (response.equals("BLACK"))
                        {
                            final CustomMaterialDialog dialog = new CustomMaterialDialog(Login.this);
                            dialog.setMessage("由于您的违规操作，您已经被列入黑名单中，请规范您的操作行为！")
                                    .setCanBack(false)
                                    .setButtonText("退出")
                                    .setButtonOnClick(new OnBtnClickL()
                                    {
                                        @Override
                                        public void onBtnClick()
                                        {
                                            dialog.dismiss();
                                            new Handler().postDelayed(new Runnable()
                                            {
                                                @Override
                                                public void run()
                                                {
                                                    finish();
                                                }
                                            }, 200);
                                        }
                                    }).show();
                        }
                        else if (response.equals("NULL_PHONE"))
                        {
                            SuperToast.buttonToast(Login.this)
                                    .setBackgroundColor(ButtonToast.Background.RED)
                                    .setText("没有该账号，请您前往注册！")
                                    .setDuration(ButtonToast.Duration.LONG)
                                    .setOnClick(new OnClick()
                                    {
                                        @Override
                                        public void onClick(View view, Parcelable parcelable)
                                        {
                                            scrollView.smoothScrollTo(0, 2 * Utils.getScreenHeight());
                                        }
                                    })
                                    .show();
                            submit.setProgress(-1);
                        }
                    }
                });
    }


    */
/**
     * 保存用户信息
     *//*

    private void saveUserInformation()
    {
        SharedPreferences sharedPreferences = getSharedPreferences("user", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        if (rememberPassword.isChecked())
        {
            editor.putString("un", Encryp_AES.encryptCode(userPhoneNum.getText().toString()));
            editor.putString("up", Encryp_AES.encryptCode(userPassword.getText().toString()));
            editor.putString("ui", Encryp_AES.encryptCode(Utils.getIMEI()));
            editor.apply();
        }
        else
        {
            editor.putString("un", "");
            editor.putString("up", "");
            editor.putString("ui", Encryp_AES.encryptCode(Utils.getIMEI()));
            editor.apply();
        }
    }

    */
/**
     * 读取用户信息
     *//*

    private void readUserInformation()
    {
        final SharedPreferences sharedPreferences = getSharedPreferences("user", MODE_PRIVATE);
        final String imei = sharedPreferences.getString("ui", "");
        if (!imei.equals(""))
        {
            final String _imei = Encryp_AES.decryptCode(imei);
            new SAcp()
            {
                @Override
                public void onGranteds()
                {
                    if (_imei.equals(Utils.getIMEI()))
                    {
                        String un = sharedPreferences.getString("un", "");
                        String up = sharedPreferences.getString("up", "");
                        if (!un.equals(""))
                            userPhoneNum.setText(Encryp_AES.decryptCode(un));
                        if (!up.equals(""))
                        {
                            userPassword.setText(Encryp_AES.decryptCode(up));
                            rememberPassword.setChecked(true);
                        }
                    }
                }

                @Override
                public void onDenieds()
                {
                    SAcp.showDialog(Login.this, Login.this);
                }
            }.getPermissions(Manifest.permission.READ_PHONE_STATE);
        }
    }

    */
/**
     * 设置 记住密码 和 忘记密码
     *//*

    private void setCheckBox()
    {
        forgetPassword.setOnClickListener(view -> {
            //startActivity(new Intent());
            Utils.Toast("暂未开启！");
        });
    }


    */
/**
     * 下拉注册动画
     *//*

    private void setPull_down()
    {
        pull_down.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                scrollView.smoothScrollTo(0, 2 * Utils.getScreenHeight());
            }
        });

        Animation animation = new TranslateAnimation(0, 0, 0, 50);
        animation.setInterpolator(new AccelerateInterpolator());
        animation.setDuration(1000);
        animation.setRepeatMode(Animation.REVERSE);
        animation.setRepeatCount(Integer.MAX_VALUE);

        pull_down.startAnimation(animation);
    }

    */
/**
     * 高斯模糊
     *//*

    private void setupBlurView()
    {
        float radius = 16f;

        View decorView = getWindow().getDecorView();
        View rootView = decorView.findViewById(android.R.id.content);
        Drawable windowBackground = decorView.getBackground();

        blurView.setupWith(rootView)
                .windowBackground(windowBackground)
                .blurAlgorithm(new RenderScriptBlur(this, true)) //Preferable algorithm, needs RenderScript support mode enabled
                .blurRadius(radius);
    }
}
*/
